﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using PoemGameWebApiService.Shared;
using static System.Collections.Specialized.BitVector32;

namespace PoemGame.Domain.Services.Factory.WebApi
{
    public class CheckGameConditionServiceRemote:ICheckGameConditionService
    {
        private readonly HttpClient _httpClient;
        private readonly string url;

        public CheckGameConditionServiceRemote(HttpClient httpClient, string url)
        {
            _httpClient = httpClient;
            this.url = url;
        }

        public async Task<bool> CheckGameCondition(string condition)
        {
            var dto = new CheckConditionServiceDto { Condition = condition };
            var str= JsonSerializer.Serialize(dto);
            var content = new StringContent(str);
            content.Headers.ContentType=new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            var response = await _httpClient.PostAsync(url,content);
            response.EnsureSuccessStatusCode();
            var res = await response.Content.ReadAsStringAsync();
            return bool.Parse(res);

        }
    }
}
